
<%@page import="ll.sms.web.*"%><%@ page language="java"
	import="java.util.*,ll.sms.pojo.*,org.json.simple.*"
	pageEncoding="UTF-8"%>
<%@page import="ll.sms.util.*,org.apache.commons.lang.*"%>
<%
	String sort = ParamUtils.getParameter(request, "sort");
	int index = ParamUtils.getIntParameter(request, "start", 0);
	int pageSize = ParamUtils.getIntParameter(request, "limit", 15);

	String name = ParamUtils.getParameter(request,"username");
	String toname = ParamUtils.getParameter(request,"tousername");//limao
	String msendtime = ParamUtils.getParameter(request,"msendtime");
	String msendtime_1 = ParamUtils.getParameter(request,"msendtime_1");
	String channel = ParamUtils.getParameter(request,"channel_");
	String sendstatustr = ParamUtils.getParameter(request,"sendstatu");

	int sendstatu = (sendstatustr==null||sendstatustr.trim().equals(""))?0:SmsUtil.toInt(sendstatustr);

	int currentPage = 1 + (index / pageSize);
	String dir = request.getParameter("dir");
	if (dir == null) {
		dir = "ASC";
	}

	String orderStr = " maddtime DESC ";
	if (sort != null && !sort.equals("")) {
		orderStr = " ," + sort + " " + dir + " ";
	}
	StringBuffer condition = null;
	String currentUsername = SmsUtil.sessionHelper(session,AdminProperty.auname);
	if(!"admin".equals(currentUsername)){
	//代理
	condition=new StringBuffer(" where mproxyid='"+SmsUtil.sessionHelper(session,AdminProperty.aid)+"' and");
	}else{
	condition=new StringBuffer(" where ");
	}
	
	if(!StringUtils.isBlank(name)){
		condition.append(" mfrom = '").append(name).append("' ");
	}else{
		condition.append(" 1=1 ");
	}
	condition.append("and");
	if(!StringUtils.isBlank(toname)){
		condition.append(" mto like '%").append(toname).append("%' ");
	}else{
		condition.append(" 1=1 ");
	}
	condition.append("and");
	if(!StringUtils.isBlank(msendtime) && !StringUtils.isBlank(msendtime_1)){
		condition.append(" msendtime >to_date('").append(msendtime).append("','yyyy-mm-dd hh24:mi:ss') ");
		condition.append("and").append(" msendtime<to_date('").append(msendtime_1).append("','yyyy-mm-dd hh24:mi:ss') ");
	}else{
		condition.append(" 1=1 ");
	}
	condition.append("and");
	if(!StringUtils.isBlank(channel) && !channel.equals("NA")){

		condition.append(" mchannel = '" +channel+"' ");

	}else{
		condition.append(" 1=1 ");
	}
	condition.append("and");
	if(sendstatu ==-2){//失败
	condition.append(" mstatue = -2");
	}else if(sendstatu==1){//成功
		//其实成功还包括admin的取消
	condition.append(" mstatue = 1 or mstatue = -1");
	}else if(sendstatu==-1){//代理的取消
		condition.append(" mstatue = -3");
	}else{
		condition.append(" 1=1 ");
	}

	int total = WebBusinessImpl.getInstance().countTable("sms_message",
			condition.toString());
	String s = ExtJsonBuilder.toExtJsonString(total, WebBusinessImpl
			.getInstance().pageQuery(SmsMessage.class,"sms_message",condition.toString(),currentPage,pageSize,orderStr));
	response.getWriter().print(s);
%>
